package br.inf.mensageiro.multicast;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

import br.inf.mensageiro.context.ApplicationContext;
import br.inf.mensageiro.pojo.Status;
import br.inf.mensageiro.util.Parametro;

public class ServerMulticast {
	
	public static void send(Status status) throws IOException {
		String alias = ApplicationContext.getInstance().getAlias();
		String userName=System.getProperty("user.name");
		StringBuffer mensagem = new StringBuffer(status.name());
		mensagem.append("|").append(userName).append("|").append(alias);
		InetAddress address = InetAddress.getByName(Parametro.HOST_BROADCAST);
		DatagramSocket datagramSocket = new DatagramSocket();
		DatagramPacket datagramPacket = new DatagramPacket(mensagem.toString().getBytes(), mensagem.length(), address, Parametro.PORT_BROADCAST);
		datagramSocket.send(datagramPacket);
	}
	
}